$(function () {
    UserPermission();
     LoginOout();

})
// 个人中心的js

function UserPermission() {
    // console.log(localStorage.token, sessionStorage.token)
    if (localStorage.token == undefined && sessionStorage.token == undefined){
        // 未登录状态 返回登陆页 不让进入个人中心
        location.href = './login.html';

    }else {
    //    登陆状态 隐藏登陆 注册  展开个人中心
        $('.user_login_in_hidden').css("display", "none")
        $('.user_login_on').css("display", "")
        $('.user_login_on_a').text(localStorage.username || sessionStorage.username).css('color', '#40D2B1')
        var token = localStorage.token || sessionStorage.token

        $.ajax({
            url: host + "/user_details/",
            method: "get",
            data: {},
            headers: {'Authorization': 'JWT ' + token},
            contentType: "application/json",
            xhrFields: {
                withCredentials: true
            },
            success: function (resp) {
                // console.log(resp)
                $('#user_nick_name').html(resp.nickname)
                $('#user_sex').html(resp.sex)
                $('#user_mobile').html(resp.mobile)
                $('#user_email').html(resp.email)
                $('#user_address').html(resp.address)
                if (resp.email_active ==true){
                    $('#user_email_active').html('已验证').attr('disabled','disabled')
                }

            },
            error: function (resp) {
                location.href = '/login.html';

            }
        })





    }

}

function LoginOout() {
    $(".login_out").click(function () {
        sessionStorage.clear();
        localStorage.clear();
        location.reload()
    })
}

